package com.example.concurrentprogramming8016.CountDownLatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author liyanhao
 * @Date 2023-01-06 20:46
 */
public class CountDownLatchDemo2 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(5);
        for (int i = 0; i < 5; i++) {
            int finalI = i;
            new Thread(() -> {
                try {
                    TimeUnit.SECONDS.sleep(1 + finalI);
                    countDownLatch.countDown();
                    System.out.println("等待"+finalI+"秒减少一个");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }).start();
        }
        countDownLatch.await();
        System.out.println("全部减少await等待结束");
    }
}
